Compilation combines a set of operations with the objective of converting a set of instructions that can be read by a human being forming a computer program into a machine code, that is to say a set of instructions that can be read by a target device. Hereinafter in the description, the target device is simply called target and corresponds, for example, to a processor.
Compilation can be described in a simplified way as a succession of three steps. A first step checks the syntax of the source code and translates it into a non-optimized intermediate representation.
A second compilation step combines a set of optimization operations that are independent of the target. An example of optimization consists in unfolding the instruction loops in such a way as to allow them to be executed sequentially. The code that is thus obtained then corresponds to an optimized intermediate representation (OIR).
A third step transforms the optimized intermediate representation into machine code, for example into assembly language. Optimizations can also be performed at this stage.
Dynamic compilation techniques are now used. This means that one or more compilation steps are applied at the time of the execution of the computer program by the target. These techniques make it possible to adapt a computer program with which a source code is associated in such a way that the latter can be executed on different targets requiring different machine codes. These techniques also make it possible to adapt a computer program in order to optimize it according to the conditions of use. The compilation step or steps implemented at the time of the execution of the program can use as input the source code, an optimized or non-optimized intermediate representation, or else a machine code to be translated for a new target requiring a different machine code or to be optimized for the current target.
In the field of embedded information technology, certain constraints have to be taken into account for the use of applications. In practice, a handheld device such as a smartphone usually has specialized computation resources, resulting from a design matched to a specific use. Furthermore, its energy consumption has to be optimized in order to guarantee a sufficient power reserve.
The dynamic compilation algorithms exhibit great irregularity. In practice, the representation in memory of the instruction flow to be processed is complex by virtue of the successive optimizations which fragment the representation of the instruction flow. It is then often difficult to predict in advance the location and the nature of the different instructions that make up the instruction flow as input. The embedded processors do not have mechanisms making it possible to manage this irregularity. The loading and decoding steps performed on the input instruction flow are particularly costly in terms of execution times on these processors because they are numerous and irregular.
By way of example, for some applications in the embedded technology field, an intermediate code is downloaded by a mobile terminal. Examples of intermediate codes are the Java byte code, the CIL (Common Infrastructure Language) byte code and the LLVM (LowLevel Virtual Machine) byte code. After having been optimized and transformed into machine code, the application can be directly executed on the target. This solution has the advantage of minimizing the quantity of memory needed to store the application on the mobile terminal. In effect, the intermediate code can be adapted so that it takes less space than the machine code of the application. Furthermore, that also avoids storing in memory different machine codes for the application in memory where a heterogeneous architecture is concerned, that is to say an architecture comprising a plurality of computation units with different instruction sets.
However, the implementation of the dynamic compilation techniques in the embedded technology field often involves a degradation of performance levels. In particular, the total execution time including phases of compilation and of execution of the applications is lengthened because of the great complexity of the algorithms and the memory occupancy is not optimized.